@extends('frontend.layouts.user_panel')

@section('panel_content')
    <div class="aiz-titlebar mt-2 mb-4">
        <div class="row align-items-center">
            <div class="col-md-6">
                <b class="h3">{{ translate('affiliate_logs')}}</b>
            </div>
        </div>
    </div>

    <div class="card-body" style="background: #FFF">
        <table class="table aiz-table mb-0">
            <thead>
            <tr>
                <th>#</th>
                <th data-breakpoints="lg">{{ translate('Referred By')}}</th>
                <th>{{ translate('Referral User')}}</th>
                <th>{{ translate('Amount')}}</th>
                <th>{{ translate('Freeze Funds')}}</th>
                <th data-breakpoints="lg">{{ translate('Order Id')}}</th>
                <th data-breakpoints="lg">{{ translate('Referral Type') }}</th>
                {{--                    <th data-breakpoints="lg">{{ translate('Product') }}</th>--}}
                <th data-breakpoints="lg">{{ translate('Date') }}</th>
            </thead>
            <tbody>
            @foreach($affiliate_logs as $key => $affiliate_log)
                @if ($affiliate_log->user != null)
                    <tr>
                        <td>{{ ($key+1) + ($affiliate_logs->currentPage() - 1)*$affiliate_logs->perPage() }}</td>
                        <td>
                            {{ optional(\App\Models\User::where('id', $affiliate_log->referred_by_user)->first())->name }}
                        </td>
                        <td>
                            @if($affiliate_log->user_id !== null)
                                {{ optional($affiliate_log->user)->name }}
                            @else
                                {{ translate('Guest').' ('. $affiliate_log->guest_id.')' }}
                            @endif
                        </td>
                        <td>{{ single_price($affiliate_log->amount) }}</td>
                        <td>{{ single_price($affiliate_log->freeze_funds) }}</td>
                        <td>
                            @if($affiliate_log->order_id != null)
                                {{ optional($affiliate_log->order)->code }}
                            @else

                                {{--                                    {{ optional($affiliate_log->order_detail->order)->code }}--}}
                            @endif
                        </td>
                        <td>{{translate($affiliate_log->affiliate_type)}} </td>
                        {{--                            <td>--}}
                        {{--                                @if($affiliate_log->order_detail_id != null && $affiliate_log->order_detail)--}}
                        {{--                                    {{ optional($affiliate_log->order_detail->product)->name }}--}}
                        {{--                                @endif--}}
                        {{--                            </td>--}}
                        <td>{{ $affiliate_log->created_at->format('Y-m-d H:i') }} </td>
                    </tr>
                @endif
            @endforeach
            </tbody>
        </table>
        <div class="aiz-pagination">
            {{ $affiliate_logs->links() }}
        </div>
    </div>
@endsection

